<template>
  <div class="app-container">
    <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px" :label-position="labelPosition">
      <el-form-item label="单号" prop="pzbh">
        <el-input
          v-model="queryParams.pzbh"
          placeholder="请输入单号"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="柜号/批号" prop="spgh">
        <el-input
          v-model="queryParams.spgh"
          placeholder="请输入柜号/批号"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="仓库" prop="spckmc">
        <el-select
            v-model="queryParams.spckmc"
            placeholder="请选择"
            clearable
            @change="changeWarehouse"
            filterable
            :loading="selectWarehouse15Loading || loading"
        >
            <el-option
                v-for="item in warehouseList"
                :key="item.spckid"
                :label="item.spckmc"
                :value="item.spckid"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="车牌" prop="dzzy6">
        <el-input
          v-model="queryParams.dzzy6"
          placeholder="请输入车牌"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="入仓日期" prop="warehouseInDate">
        <el-date-picker
          v-model="warehouseInDate"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="warehouseInDateChange()">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
     <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" @click="handleSceneWarehouseIn" v-hasPermi="['zhcloud:hwrc:add']">入仓办单</el-button>
        </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="warehouseInList"
    >
      <af-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150" fixed="left">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleOpenDetail(scope.row)"
            v-hasPermi="['zhcloud:hwrc:detail']"
          >详细</el-button>
        </template>
      </af-table-column>
      <af-table-column prop="dzzy9" label="打印次数"  fixed="left"></af-table-column>
      <af-table-column prop="yydh" label="关联单号" ></af-table-column>
      <af-table-column prop="wbdh" label="外部单号" ></af-table-column>
      <af-table-column prop="pzbh" label="单号" ></af-table-column>
      <af-table-column prop="ssrqid" label="入仓日期" ></af-table-column>
      <af-table-column prop="khmc" label="客户" ></af-table-column>
      <af-table-column prop="spjs" label="入仓件数" ></af-table-column>
      <af-table-column prop="spsl" label="入仓重量(吨)" ></af-table-column>
      <af-table-column prop="spzs" label="物品规格" ></af-table-column>
      <af-table-column prop="dzzy6" label="车牌" ></af-table-column>
      <af-table-column prop="rsopmc" label="创建人" ></af-table-column>
      <af-table-column prop="prrq" label="创建时间" ></af-table-column>
      <af-table-column prop="shrqid" label="审核日期" ></af-table-column>
      <af-table-column prop="shrsmc" label="审核人" ></af-table-column>
      <af-table-column prop="dzbz" label="备注"  width="150" :show-overflow-tooltip="true"></af-table-column>
      <af-table-column prop="shzt" label="审核状态" ></af-table-column>
    </el-table>
     <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
  </div>

</template>

<script>
import { ListWarehouseIn } from "@/api/storage/commonGoods/warehouseIn";
import { selectWarehouse15 } from "@/api/storage/warehouse"

export default {
  name: "CWarehouseIn",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //表格加载
      loading:true,
      //仓库加载
      selectWarehouse15Loading:true,
      //对齐
      labelPosition: "right",
      warehouseInDate:'',
      // 查询参数
      queryParams: {
        ckcw: "",
        dzzy6: "",
        jqcz: "",
        pzbh: "",
        pzbh1: "",
        rqid1: "",
        rqid2: "",
        shzt: "",
        spbh: "",
        spckmc: "",
        spgh: "",
        spkhmc: "",
        spkhmc1: "",
        sptm: "",
        ssrqid: "",
        wbdh: ""
      },
      // 货物入仓列表
      warehouseInList: [],
      //仓库列表
      warehouseList:[],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    const params = to.params
    next(vm => {   
      if(Object.keys(params).length > 0) {
        if(to.params.refresh == true) {
          const user = vm.$store.getters.user
          if(user.shopName) {
            vm.queryParams.spkhmc = user.shopName
            vm.queryParams.khmcid = user.shopId
            vm.getList()
          }
        }
      }
    })
  },
  created() {
    const user = this.$store.getters.user
    this.getWarehouse()
    if(user.shopName) {
      this.queryParams.spkhmc = user.shopName
      this.queryParams.khmcid = user.shopId
      this.getList()
    } 
  },
  methods: {
    /**获取仓库 */
    getWarehouse() {
      this.selectWarehouse15Loading = true
      selectWarehouse15({}).then(response => {
        this.warehouseList = response.data
        this.selectWarehouse15Loading = false
      });
    },
    /** 查询货物入仓列表 */
    getList() {
      this.loading = true
      ListWarehouseIn(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.warehouseInList = response.rows;
        this.total = response.total;
        this.loading = false
      });
    },

    /**选择仓库 */
    changeWarehouse(id) {
      this.getList()
    },

     /**选择入仓时间 */
    warehouseInDateChange() {
      this.queryParams.rqid1 = this.warehouseInDate?this.warehouseInDate[0]:""
      this.queryParams.rqid2 = this.warehouseInDate?this.warehouseInDate[1]:""
      this.getList()
    },

    /** 现场入仓*/
    handleSceneWarehouseIn() {
      this.$router.push({path:"/cStorage/warehouseIn/sceneWarehouseIn", query:{
        spkhmc:this.queryParams.spkhmc,
        khmcid:this.queryParams.khmcid
      }})
    },

    /**详情 */
    handleOpenDetail(row) {
      this.$router.push({path:"/cStorage/warehouseIn/warehouseInDetail", query:{
        dzid:row.dzid,
      }})
    },

    /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getWarehouse()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
  }
};
</script>
